package com.topten.dao.especificos;

import java.util.List;

import javax.persistence.TypedQuery;

import com.topten.basicas.comum.Situacao;
import com.topten.basicas.varejo.Loja;
import com.topten.dao.generico.DAOGenerico;

public class DAOLoja extends DAOGenerico<Loja> implements IDAOLoja {

	@Override
	public List<Loja> pesquisarLojaPorCNPJ(String cnpj) {
		
		String consulta = "Select l from Loja l where l.documento1=:cnpjConsulta";
		TypedQuery<Loja> query = entityManager.createQuery(consulta, Loja.class);
		query.setParameter("cnpjConsulta", cnpj);
		return query.getResultList();
	}

	@Override
	public List<Loja> buscarLojaPorNome(String nome) {
		String jpql = "Select l from Loja l where l.nome like :nom";
		TypedQuery<Loja> query = entityManager.createQuery(jpql, Loja.class);
		query.setParameter("nom", nome + "%");
		return query.getResultList();
	}

	@Override
	public List<Loja> listarTodasAtivas(Enum<Situacao> situ) {
		String jpql = "Select l from Loja l where l.situacao=:situa";
		TypedQuery<Loja> query = entityManager.createQuery(jpql, Loja.class);
		query.setParameter("situa", situ);
		return query.getResultList();
	}

}
